import java.util.Scanner;

public class Main {
    public static int GetMax(int a,int b){
        return (a)>(b) ? (a) : (b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        //向新建的数组中放入数据
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = sc.nextInt();
        }
        int sum = array[0];
        //让max初始值为array[0]，是为了防止出现第一个数为正，第二个数为负的情况；
        int max = array[0];

        for (int i = 1; i < size; i++) {
            sum = GetMax(sum + array[i],array[i]);
            if (sum >= max){
                max = sum;
            }
        }
        System.out.println(max);
    }
}
